<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: css_styler.php 169 2013-09-22 07:54:38Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 169 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:54:38 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require_once('includes/application_top.php');

$css_cache_datei = DIR_FS_CATALOG.'cache/mercari_buttons.css';
$erzeuge_cache = false;

if(file_exists($css_cache_datei) == false)
	$erzeuge_cache = true;
elseif(filesize($css_cache_datei) < 10)
	$erzeuge_cache = true;
elseif(filemtime($css_cache_datei) < time() - 86400)
	$erzeuge_cache = true;

if($erzeuge_cache !== false) {

	function getHex($value) {
		$v = substr($value,0,6);
		return '#'.$v;
	}
	if(CSS_BUTTON_ACTIVE == 'true') {
		if(CSS_BUTTON_BACKGROUND_1 !='' || CSS_BUTTON_BACKGROUND_2 !='')
			$background = ' url(templates/images/live-'.str_replace('#', '', CSS_BUTTON_BACKGROUND_1).'-'.str_replace('#', '', CSS_BUTTON_BACKGROUND_2).(CSS_BUTTON_BACKGROUND_3 !='' ? '-'.str_replace('#', '', CSS_BUTTON_BACKGROUND_3).'-'.str_replace('#', '', CSS_BUTTON_BACKGROUND_4):'').'_32x1.jpg) repeat-x center left';
		elseif(CSS_BUTTON_BACKGROUND_PIC !='')
			$background = ' url(images/css_button_bg/'.CSS_BUTTON_BACKGROUND_PIC.') repeat-x center left';

		$css = 'button.css_img_button,a span.css_img_button{';
		$css .= 'background:'.CSS_BUTTON_BACKGROUND.$background.';';

		if(CSS_BUTTON_BORDER_WIDTH > 0 && CSS_BUTTON_BORDER_STYLE !='none')
			$css .= 'border:'.CSS_BUTTON_BORDER_WIDTH.' '.CSS_BUTTON_BORDER_STYLE.' '.CSS_BUTTON_BORDER_COLOR.';';
		else
			$css .= 'border: 0;';

		$css .= 'color:'.CSS_BUTTON_FONT_COLOR.';
			cursor:pointer;
			font-family: '.CSS_BUTTON_FONT_FAMILY.';'
			.(CSS_BUTTON_FONT_SIZE!='' ? 'font-size:'.CSS_BUTTON_FONT_SIZE.';' : '').'
			display:inline-block;
			line-height:normal;'
			.((CSS_BUTTON_FONT_ITALIC == 'true') ? 'font-style: italic;' : '').
			'padding: 5.5px 10px;
			text-align:center !important;
			white-space:nowrap;';
		if(CSS_BUTTON_BORDER_RADIUS !='')
			$css .= '-moz-border-radius:'.CSS_BUTTON_BORDER_RADIUS.';-webkit-border-radius:'.CSS_BUTTON_BORDER_RADIUS.';border-radius:'.CSS_BUTTON_BORDER_RADIUS.';';
		if(CSS_BUTTON_FONT_SHADOW !='')
			$css .= 'text-shadow:'.CSS_BUTTON_FONT_SHADOW.';';
		if(CSS_BUTTON_MISC !='')
			$css .= CSS_BUTTON_MISC;
		$css .= '}';

		$css .= 'button.css_img_button{padding: 4.5px 4px;}';
		$css .= 'a:hover .css_img_button, button.css_img_button:hover {';

		if(CSS_BUTTON_HOVER_BACKGROUND_1 !='' || CSS_BUTTON_HOVER_BACKGROUND_2 !='')
			$background_hover = ' url(templates/images/live-'.str_replace('#', '', CSS_BUTTON_HOVER_BACKGROUND_1).'-'.str_replace('#', '', CSS_BUTTON_HOVER_BACKGROUND_2).(CSS_BUTTON_HOVER_BACKGROUND_3 !='' ? '-'.str_replace('#', '', CSS_BUTTON_HOVER_BACKGROUND_3).'-'.str_replace('#', '', CSS_BUTTON_HOVER_BACKGROUND_4):'').'_32x1.jpg) repeat-x center left';
		elseif(CSS_BUTTON_BACKGROUND_HOVER !='' || CSS_BUTTON_BACKGROUND_PIC_HOVER !='') {
			if(CSS_BUTTON_BACKGROUND_PIC_HOVER !='')
				$background_hover = ' url(images/css_button_bg/'.CSS_BUTTON_BACKGROUND_PIC_HOVER.') repeat-x scroll center left';
		}
		$css .= 'background:'.CSS_BUTTON_HOVER_BACKGROUND_1.' '.CSS_BUTTON_BACKGROUND_HOVER.$background_hover . ';';
		if(CSS_BUTTON_BORDER_COLOR_HOVER !='')
			$css .= 'border-color:'.CSS_BUTTON_BORDER_COLOR_HOVER.';';
		if(CSS_BUTTON_FONT_COLOR_HOVER!='')
			$css .= 'color:'.CSS_BUTTON_FONT_COLOR_HOVER.';';
		$css .= '}';

		$css .= '* html .css_img_button { padding: 1px 2px 2px 2px; }
				* html button.css_img_button { padding: 1px 2px 2px 2px; margin: -2px 1px;}';
		$css .= 'a.css_img_button:link,a.css_img_button:visited,a.css_img_button:active,a:hover .css_img_button { text-decoration: none; }';
		
		if(CSS_CART_BUTTON_BACKGROUND_1 !='' || CSS_CART_BUTTON_BACKGROUND_2 !='')
			$background = CSS_CART_BUTTON_BACKGROUND_1.' url(templates/images/live-'.str_replace('#', '', CSS_CART_BUTTON_BACKGROUND_1).'-'.str_replace('#', '', CSS_CART_BUTTON_BACKGROUND_2).(CSS_CART_BUTTON_BACKGROUND_3 !='' ? '-'.str_replace('#', '', CSS_CART_BUTTON_BACKGROUND_3).'-'.str_replace('#', '', CSS_CART_BUTTON_BACKGROUND_4):'').'_40x1.jpg) repeat-x 0 100%';
		elseif(CSS_CART_BUTTON_BACKGROUND_PIC !='')
			$background = ' url(images/css_button_bg/'.CSS_CART_BUTTON_BACKGROUND_PIC.') repeat-x 0 50%';
		else
			$background = CSS_CART_BUTTON_BACKGROUND;
		$css .= 'button.css_cart_img_button{';
		$css .= 'background:'.$background.';';

		if(CSS_CART_BUTTON_BORDER_WIDTH > 0 && CSS_CART_BUTTON_BORDER_STYLE !='none')
			$css .= 'border:'.CSS_CART_BUTTON_BORDER_WIDTH.' '.CSS_CART_BUTTON_BORDER_STYLE.' '.CSS_CART_BUTTON_BORDER_COLOR.';';
		else
			$css .= 'border: 0;';

		$css .= 'color:'.CSS_CART_BUTTON_FONT_COLOR.';
			cursor:pointer;
			font-family: '.CSS_CART_BUTTON_FONT_FAMILY.';'
			.(CSS_CART_BUTTON_FONT_SIZE!='' ? 'font-size:'.CSS_CART_BUTTON_FONT_SIZE.';' : '').'
			display:inline-block;
			line-height:24px;'
			.((CSS_CART_BUTTON_FONT_ITALIC == 'true') ? 'font-style: italic;' : '').
			'padding:6px;
			text-align:center !important;
			white-space:nowrap;';
		if(CSS_CART_BUTTON_BORDER_RADIUS !='')
			$css .= '-moz-border-radius:'.CSS_CART_BUTTON_BORDER_RADIUS.';-webkit-border-radius:'.CSS_CART_BUTTON_BORDER_RADIUS.';border-radius:'.CSS_CART_BUTTON_BORDER_RADIUS.';';
		if(CSS_CART_BUTTON_FONT_SHADOW !='')
			$css .= 'text-shadow:'.CSS_CART_BUTTON_FONT_SHADOW.';';
		if(CSS_CART_BUTTON_MISC !='')
			$css .= CSS_CART_BUTTON_MISC;
		$css .= '}';

		$css .= 'button.css_cart_img_button:hover {';
		if(CSS_CART_BUTTON_HOVER_BACKGROUND_1 !='' || CSS_CART_BUTTON_HOVER_BACKGROUND_2 !='')
			$background_hover = ' url(templates/images/live-'.str_replace('#', '', CSS_CART_BUTTON_HOVER_BACKGROUND_1).'-'.str_replace('#', '', CSS_CART_BUTTON_HOVER_BACKGROUND_2).(CSS_CART_BUTTON_HOVER_BACKGROUND_3 !='' ? '-'.str_replace('#', '', CSS_CART_BUTTON_HOVER_BACKGROUND_3).'-'.str_replace('#', '', CSS_CART_BUTTON_HOVER_BACKGROUND_4):'').'_40x1.jpg) repeat-x 0 100%';
		elseif(CSS_CART_BUTTON_BACKGROUND_HOVER !='' || CSS_CART_BUTTON_BACKGROUND_PIC_HOVER !='') {
			if(CSS_CART_BUTTON_BACKGROUND_PIC_HOVER !='')
				$background_hover = ' url(images/css_button_bg/'.CSS_CART_BUTTON_BACKGROUND_PIC_HOVER.') repeat-x scroll 0 50%';
		}
		$css .= 'background:' . CSS_CART_BUTTON_BACKGROUND_HOVER.$background_hover . ';';
		if(CSS_CART_BUTTON_BORDER_COLOR_HOVER !='')
			$css .= 'border-color:'.CSS_CART_BUTTON_BORDER_COLOR_HOVER.';';
		if(CSS_CART_BUTTON_FONT_COLOR_HOVER!='')
			$css .= 'color:'.CSS_CART_BUTTON_FONT_COLOR_HOVER.';';
		$css .= '}';

		$css .= '* html .css_cart_img_button { padding: 1px 2px 2px 2px; }';		

	} elseif (CSS_BUTTON_ACTIVE == 'text') {
		$css  = 'button.css_img_button, button.css_cart_img_button, a span.css_img_button {';
		$css .= 'border: none 0;';
		$css .= 'background: none;';
		$css .= 'color: '.CSS_BUTTON_FONT_COLOR.';';
		$css .= 'cursor: pointer;';
		$css .= 'margin: 2px 5px;';
		$css .= '}';
		$css .= 'a:hover .css_img_button, button.css_img_button:hover {';
		$css .= 'color:'.CSS_BUTTON_FONT_COLOR_HOVER.';';
		$css .= 'text-decoration:underline;';
		$css .= '}';
	}

	$output = str_replace("\n",'',$css);
	$output = str_replace("\t",'',$output);

	$fp = fopen($css_cache_datei, 'w+');
	fwrite($fp, $output);
	fclose($fp);
}